using System;
using System.Globalization;

namespace BattlelogMobile.Core.Model
{
    public class Soldier : ISoldier
    {
        private int _wins;
        private int _losses;

        public IUser User { get; set; }
        public int Rank { get; set; }               // rank
        public double Skill { get; set; }           // elo
        public IKitProgressions KitProgressions { get; set; }
        public TimeSpan TimePlayed { get; set; }    // timePlayed
        public int ScorePerMinute { get; set; }     // scorePerMinute
        public double KillDeathRatio { get; set; }  // kdRatio
        public int Wins                             // numWins
        {
            get { return _wins; }
            set
            {
                _wins = value;
                CalculateWinLoseRatio();
            }
        }
        public int Losses                           // numLosses
        {
            get { return _losses; }
            set
            {
                _losses = value;
                CalculateWinLoseRatio();
            }
        }             

        public double WinLoseRatio { get; set; }
        public IScore Score { get; set; }
        public int Kills { get; set; }              // kills
        public IItems TopWeapons { get; set; }
        public IItems TopVehicles { get; set; }
        public IItems TopGadgets { get; set; }

        private void CalculateWinLoseRatio()
        {
            if (_wins > 0 && _losses > 0)
                WinLoseRatio = Convert.ToDouble(_wins, CultureInfo.InvariantCulture) / Convert.ToDouble(_losses, CultureInfo.InvariantCulture);
            else
                WinLoseRatio = 0d;
        }

        public IAwards Awards { get; set; }
        public IStatistics Statistics { get; set; }

        public override string ToString()
        {
            return
                string.Format(
                    "User=[{0}], Rank={1}, TimePlayed={2}, Skill={3}, Kills={4}, KillDeathRatio={5}, Wins={6}, " +
                    "Losses={7}, WinLoseRatio={8}, Score=[{9}], ScorePerMinute={10}, KitProgressions=[{11}],  " + 
                    "TopWeapons={12}, TopVehicles=[{13}], TopGadgets=[{14}], Awards=[{15}], Statistics=[{16}]", 
                    User, Rank, TimePlayed.ToString(), Skill, Kills, KillDeathRatio, Wins, Losses, WinLoseRatio,
                    Score, ScorePerMinute, KitProgressions, TopWeapons, TopVehicles, TopGadgets, Awards, Statistics);
        }
    }
}